using FubuMVC.Core.Results;

namespace FubuMVC.Core.Behaviors
{
    public class RedirectToNotFoundUrl : IActionBehavior
    {
        private readonly string _pageNotFoundUrl;
        private readonly ICurrentResult _result;

        public RedirectToNotFoundUrl(string pageNotFoundUrl, ICurrentResult result)
        {
            _pageNotFoundUrl = pageNotFoundUrl;
            _result = result;
        }

        public IActionBehavior InsideBehavior { get; set; }

        public void Invoke() 
        {
            _result.OverrideIfNotAlreadyOverriden(new RedirectResult(_pageNotFoundUrl));
        }
    }
}